<?php
include('includes/Dictionary.class.php');
$dictionary = new Dictionary();

$actionFlag = 0; #no change by default

if (isset($_POST['q'])) {

	$actionFlag = -1; #assume it fails
	
	$q = $_POST['q']; #query-type
	if (isset($_POST['w'])) {
		$w = $_POST['w']; #word
	}
	if (isset($_POST['d'])) {
		$d = $_POST['d']; #definition
	}
	
	switch ($q) {
		case 'add':
			if (isset($w) && isset($d)) {
				$dictionary->addWord($word, $definition); #execute add query
				$actionFlag = 1; #succesfully added
			}
			break;
		case 'delete':
			if (isset($w)) {
				$dictionary->deleteWord($word); #execute delete query
				$actionFlag = 1; #succesfully deleted
			}
			break;
		case 'update':
			if (isset($w) && isset($d)) {
				$dictionary->updateWord($word, $definition); #execute update query
				$actionFlag = 1; #succesfully updated
			}
			break;
	}
	
}

echo "<h1>Woordenlijst</h1>";

$dictionary->listWords(); #always list words

?>